import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:
 * Date: 2024-10-29
 * Time: 15:05
 */
public class Test {
    public static void func(String str1, String str2){
        str1 = str1.toUpperCase(Locale.ROOT);
        str2 = str2.toUpperCase(Locale.ROOT);

        HashSet<Character> setAct = new HashSet<>();
        for (int i = 0; i < str2.length(); i++) {
            char ch = str2.charAt(i);
            setAct.add(ch);
        }

        //第一步是把不同的数给挑出来，然后对于重复输出的数据给去重
        HashSet<Character> setBroken = new HashSet<>();
        for (int i = 0; i < str1.length(); i++) {
            char ch = str1.charAt(i);
            if(!setAct.contains(ch) && !setBroken.contains(ch)){
                setBroken.add(ch);
                System.out.print(ch);
            }
        }
    }

    public static void main1(String[] args) {
        func("7_This_is_a_test", "_hs_s_a_es");
    }

    public List<String> topKFrequent(String[] words, int k) {
        HashMap<String, Integer> map = new HashMap<>();
        //1.统计每个单词出现的次数
        for(String word : words){
            if(map.get(word) == null){
                map.put(word, 1);
            }else{
                int val = map.get(word);
                map.put(word, val+1);
            }
        }

        //2.建立小根堆
        PriorityQueue<Map.Entry<String, Integer>> minHeap = new PriorityQueue<>(new Comparator<Map.Entry<String, Integer>>() {
            @Override
            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                if(o1.getValue().compareTo(o2.getValue()) == 0){
                    return o2.getKey().compareTo(o1.getKey());
                }
                return o1.getValue().compareTo(o2.getValue());
            }
        });
        //3.遍历map
        for (Map.Entry<String, Integer> entry : map.entrySet()){
            if(minHeap.size() < k){
                minHeap.offer(entry);
            }else{
                Map.Entry<String, Integer> top = minHeap.peek();
                if(top.getValue().compareTo(entry.getValue()) < 0){
                    minHeap.poll();
                    minHeap.offer(entry);
                }else if(top.getValue().compareTo(entry.getValue()) == 0){
                    if(top.getKey().compareTo(entry.getKey()) < 0){
                        minHeap.poll();
                        minHeap.offer(entry);
                    }
                }
            }

        }
        ArrayList<String> list = new ArrayList<>();
        for (int i = 0; i < k; i++) {
            Map.Entry<String, Integer> tmp = minHeap.poll();
            list.add(tmp.getKey());
        }

        //e-2 f-3 a-5
        Collections.reverse(list);
        return list;
    }
}
